package com.zn.controller;

import com.zn.common.constants.Constants;
import com.zn.pojo.VeiReportInfo;
import com.zn.pojo.VeiReportInfo2;
import com.zn.services.VeiReportInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("qrcode")
public class QRCodeController {

    @Autowired
    private VeiReportInfoService veiReportInfoService;

    @RequestMapping("view1")
    public ModelAndView view1(@RequestParam("id") Integer id, @RequestParam("token") String token){
        ModelAndView mav = new ModelAndView("public/qrcode1");
        VeiReportInfo info =  veiReportInfoService.getVeiReportInfoByRidAndToken(id,token);
        if(info == null){
            return null;
        }
        mav.addObject("info",info);
        mav.addObject("token",token);
        return mav;
    }
    @RequestMapping("view2")
    public ModelAndView view2(@RequestParam("id") Integer id,@RequestParam("token") String token){
        ModelAndView mav = new ModelAndView("public/qrcode2");
        VeiReportInfo2 info =   veiReportInfoService.getVeiReportInfo2ByRidAndToken(id,token);
        if(info == null){
            return null;
        }
        mav.addObject("info",info);
        mav.addObject("token",token);
        return mav;
    }

    @RequestMapping("view_details1")
    public ModelAndView viewDetails1(@RequestParam("id") Integer id, @RequestParam("token") String token){
        ModelAndView mav = new ModelAndView("public/details1");
        VeiReportInfo info =  veiReportInfoService.getVeiReportInfoByRidAndToken(id,token);
        if(info == null){
            return null;
        }
        load_image1(info);
        mav.addObject("info",info);
        return mav;
    }

    @RequestMapping("view_details2")
    public ModelAndView viewDetails2(@RequestParam("id") Integer id, @RequestParam("token") String token){
        ModelAndView mav = new ModelAndView("public/details2");
        VeiReportInfo2 info =   veiReportInfoService.getVeiReportInfo2ByRidAndToken(id,token);
        if(info == null){
            return null;
        }
        load_image2(info);
        mav.addObject("info",info);
        if(info.getReportNumber().contains("ZNHEBA")){
            mav.setViewName("public/details2_2");
        }
        return mav;
    }

    private void load_image2(VeiReportInfo2 reportInfo){
        if(null == reportInfo){
            return;
        }
        if (!StringUtils.isEmpty(reportInfo.getPic1())) {
            reportInfo.setPic1(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic1());
        }
        if (!StringUtils.isEmpty(reportInfo.getPic2() )) {
            reportInfo.setPic2(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic2());
        }
        if (!StringUtils.isEmpty(reportInfo.getPic3() )) {
            reportInfo.setPic3(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic3());
        }
        if (!StringUtils.isEmpty(reportInfo.getPic4() )) {
            reportInfo.setPic4(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic4());
        }
        if (!StringUtils.isEmpty(reportInfo.getPic5() )) {
            reportInfo.setPic5(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic5());
        }
        if (!StringUtils.isEmpty(reportInfo.getPic6() )) {
            reportInfo.setPic6(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic6());
        }
        if (!StringUtils.isEmpty(reportInfo.getPic7() )) {
            reportInfo.setPic7(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic7());
        }
        if (!StringUtils.isEmpty(reportInfo.getPic8() )) {
            reportInfo.setPic8(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic8());
        }
        if (!StringUtils.isEmpty(reportInfo.getPic9() )) {
            reportInfo.setPic9(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic9());
        }
        if (!StringUtils.isEmpty(reportInfo.getPic10() )) {
            reportInfo.setPic10(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getPic10());
        }
    }

    private void load_image1(VeiReportInfo reportInfo){
        if(null == reportInfo){
            return;
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic1())) {
            reportInfo.setFpic1(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic1());
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic2())) {
            reportInfo.setFpic2(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic2());
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic3())) {
            reportInfo.setFpic3(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic3());
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic4())) {
            reportInfo.setFpic4(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic4());
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic5())) {
            reportInfo.setFpic5(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic5());
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic6())) {
            reportInfo.setFpic6(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic6());
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic7())) {
            reportInfo.setFpic7(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic7());
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic8())) {
            reportInfo.setFpic8(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic8());
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic9())) {
            reportInfo.setFpic9(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic9());
        }
        if (!StringUtils.isEmpty(reportInfo.getFpic10())) {
            reportInfo.setFpic10(Constants.REPORT_IMG_VIRTUAL_UTL + reportInfo.getFpic10());
        }
    }




}

